package top.tangyh.lamp.care.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.tangyh.basic.base.R;
import top.tangyh.basic.base.request.PageParams;
import top.tangyh.basic.context.ContextUtil;
import top.tangyh.basic.interfaces.echo.EchoService;
import top.tangyh.basic.base.controller.SuperController;
import top.tangyh.lamp.base.entity.user.BaseEmployee;
import top.tangyh.lamp.base.service.user.BaseEmployeeService;
import top.tangyh.lamp.care.service.BPgpfService;
import top.tangyh.lamp.care.entity.BPgpf;
import top.tangyh.lamp.care.service.DsValSevice;
import top.tangyh.lamp.care.vo.query.DeleteBactchQuery;
import top.tangyh.lamp.care.vo.query.DsInVo;
import top.tangyh.lamp.care.vo.query.PgpfQueryVO;
import top.tangyh.lamp.care.vo.result.DsOutVO;
import top.tangyh.lamp.care.vo.result.PageOutputDTO;
import top.tangyh.lamp.care.vo.result.PgpfDetailVo;
import top.tangyh.lamp.care.vo.save.BPgpfSaveVO;
import top.tangyh.lamp.care.vo.update.BPgpfUpdateVO;
import top.tangyh.lamp.care.vo.result.BPgpfResultVO;
import top.tangyh.lamp.care.vo.query.BPgpfPageQuery;
import top.tangyh.lamp.system.entity.tenant.DefUser;
import top.tangyh.lamp.system.service.tenant.DefUserService;
import top.tangyh.lamp.system.vo.query.system.DefLoginLogPageQuery;
import top.tangyh.lamp.system.vo.result.system.DefLoginLogResultVO;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * 评估评分配置主表
 * </p>
 *
 * @author zqb
 * @date 2024-07-09 11:07:34
 * @create [2024-07-09 11:07:34] [zqb]
 */
@Slf4j
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/pgpf")
@Tag(name = "评估评分-配置管理")
public class BPgpfController  {
//    extends SuperController<BPgpfService, Long, BPgpf
//            , BPgpfSaveVO, BPgpfUpdateVO, BPgpfPageQuery, BPgpfResultVO>
//    private final EchoService echoService;
//
//    @Override
//    public EchoService getEchoService() {
//        return echoService;
//    }

    private final BPgpfService bPgpfService;

    private final DsValSevice dsValSevice;

    private final DefUserService defUserService;

    @Operation(summary = "分页查询评估项")
    @PostMapping(value = "/sel/page")
    public R<PageOutputDTO<PgpfDetailVo>> anyOnePage(@RequestBody PgpfQueryVO criteria) {
        PageOutputDTO<PgpfDetailVo> pgpfVOPageOutputDTO = bPgpfService.selectPage(criteria);
        return R.success(pgpfVOPageOutputDTO);
    }



    @Operation(summary = "批量删除评估项"   )
    @PostMapping("/del")
    public R delete(   @RequestBody DeleteBactchQuery deleteBactchQuery) {
        bPgpfService.deletePgpfByIdList(deleteBactchQuery.getIds());
        return R.success();
    }

    @Operation(summary = "修改评估项")
    @PostMapping("/update")
    public R update(@RequestBody BPgpfUpdateVO resuource) {
        bPgpfService.updatePgpf(resuource);
        return R.success();
    }

    @Operation(summary = "新增评估项")
    @PostMapping("/add")
    public R add(@RequestBody BPgpfSaveVO resuource) {
        Long id = bPgpfService.addPgpf(resuource);
        return R.success(id);
    }

    @Operation(summary = "根据Id查询评估项")
    @GetMapping
    public R<BPgpfResultVO> queryById(@RequestParam Long id) {

        BPgpfResultVO bPgpfResultVO= bPgpfService.selectByPgid(id);
        //显示当前账号的名称为 评分人
        DefUser defUser = defUserService.getById( ContextUtil.getUserId());
        if(null!=defUser){
            bPgpfResultVO.setPfUserName(defUser.getNickName());
        }

        return R.success(bPgpfResultVO);
    }


    @Operation(summary =  "数据源取值查询 说明：1、观察项取值是指定时间点前一分钟内最靠近指定时间的值;2、出入量是指定时间取年月日时，在这个整点时间减去数据源2设定时间（小时），3、评估评分取的是最近一次评分数据")
    @GetMapping("/ds/val")
    public R<List<DsOutVO>> getDsVals(DsInVo resuource) {
        return R.success(dsValSevice.getDsVals(resuource));
    }

}
